<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css" />
    <title>添加新组</title>
</head>
<body>
<form class="pd-30" id="group_add">
    <div><input type="text" class="input-text" value="" id="ROLE_NAME" name="ROLE_NAME" placeholder="请输入组名进行添加"></div>
    <span id="aa" style="display: none;color: #ff032a">最多可输入20个字符</span>
    <span id="bb" style="display: none;color: #ff032a">最多可输入10个字符</span>
    <div class="text-c pd-20"><button class="btn btn-secondary radius" type="submit" id="subBtn">确定</button><a class="btn radius ml-10" href="##" onclick="cel()">取消</a></div>
</form>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript">
    function cel() {
        var index = parent.location.reload();
        parent.layer.close(index);
        sessionStorage.removeItem("groupName");
        sessionStorage.removeItem("groupEdit");
    }
        var groupId = sessionStorage.getItem("groupId");
        var groupName = sessionStorage.getItem("groupName");
        var groupEdit = sessionStorage.getItem("groupEdit");
        sessionStorage.removeItem("groupName");
        if (groupEdit == "true") {
            $("#ROLE_NAME").val(groupName);
                $("#group_add").validate({
                    /*rules: {
                        ROLE_NAME: {
                            required: true,
                            minlength: 1,
                            maxlength: 10
                        }
                    },*/

                    cache: false,
                    onkeyup: false,
                    focusCleanup: true,
                    success: "valid",
                    submitHandler: function (form) {
                        if($("#ROLE_NAME").val().length>=10){
                            $("#bb").css({
                                display: "inline"
                            });
                        }else {
                            $("#bb").css({
                                display: "none"
                            });
                        }
                        var user_data = {
                            ROLE_ID: groupId,
                            ROLE_NAME: $("#ROLE_NAME").val()
                        }
                        var succCallBack = function (data, status, response) {
                            if (data.code == 200) {
                                layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                var index = parent.location.reload();
                            } else if (data.code == 404) {
                                layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                            } else if (data.code == 400) {
                                layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                            }
                        };
                        sessionStorage.removeItem("groupEdit");
                        return web.doAjax(root.accessInter.access_editRoleGroupApi, 'post', user_data, succCallBack);
                    }
                });
        } else {
                $("#group_add").validate({
                   /* rules: {
                        ROLE_NAME: {
                            required: true,
                            minlength: 2,
                            maxlength: 20
                        }
                    },*/
                    onkeyup: false,
                    focusCleanup: true,
                    success: "valid",
                    cache: false,
                    submitHandler: function (form) {
                        if($("#ROLE_NAME").val().length>=20){
                            $("#aa").css({
                                display: "inline"
                            });
                        }else {
                            $("#aa").css({
                                display: "none"
                            });
                        }
                        $.ajax({
                            type: "POST",
                            url: root.accessInter.access_addGroupApi,
                            cache: false,
                            dataType: "json",
                            data: {
                                ROLE_NAME: $("#ROLE_NAME").val()
                            },  //传入组装的参数
                            success: function (data) {
                                switch (data.code) {
                                    case 200:
                                        layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                        var index = parent.location.reload();
                                        parent.layer.close(index);
                                    case 400:
                                        layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    case 404:
                                        layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                }
                            },
                        });
                    }
                });
        }


</script>
</body>
</html>